package com.libraries.image.adapter;

import java.util.ArrayList;

import com.libraries.image.view.PreviewImgView;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class ImagePagerAdapter  extends PagerAdapter{  
	 private ArrayList<PreviewImgView> lImageViews;
	 
    public ImagePagerAdapter(ArrayList<PreviewImgView> lImageViews) {
		this.lImageViews = lImageViews;
	}
    
    public void notifyDataSetChanged(ArrayList<PreviewImgView> lImageViews) {
    	this.lImageViews=lImageViews;
    	notifyDataSetChanged();
    };

	@Override  
    public int getCount() {  
        return lImageViews.size();  
    }  

    @Override  
    public boolean isViewFromObject(View arg0, Object arg1) {  
        return arg0 == arg1;  
    }  

    @Override  
    public void destroyItem(View container, int position, Object object) {  
        ((ViewPager)container).removeView(lImageViews.get(position));  
          
    }  

    /** 
     * 载入图片进去，用当前的position 除以 图片数组长度取余数是关键 
     */  
    @Override  
    public Object instantiateItem(View container, int position) {  
    	PreviewImgView previewImgView=lImageViews.get(position);
        ((ViewPager)container).addView(previewImgView, 0);  
        return previewImgView;  
    }  
      
}  
